package com.ruoyi.door.domain;

import java.math.BigDecimal;
import java.util.Date;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.easy.query.core.annotation.Column;
import com.easy.query.core.annotation.EntityProxy;
import com.easy.query.core.annotation.Table;
import com.easy.query.core.proxy.ProxyEntityAvailable;
import com.ruoyi.door.domain.proxy.DoorHouseProxy;

import com.ruoyi.common.core.domain.BaseEntity;

import java.util.ArrayList;

/**
 * 房产对象 door_house
 *
 * @author ruoyi
 * @date 2025-06-21
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Table("door_house")
@ApiModel(value = "房产对象", description = "房产信息")
@EntityProxy
@AllArgsConstructor
@NoArgsConstructor
@FieldNameConstants
public class DoorHouse extends BaseEntity implements ProxyEntityAvailable<DoorHouse, DoorHouseProxy>, Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @Column(primaryKey = true,generatedKey = true)
    @ApiModelProperty("主键")
    private Long id;

    /**
     * 国家
     */
    @ApiModelProperty("国家")
    private Long country;

    /**
     * 省
     */
    @Excel(name = "省")
    @ApiModelProperty("省")
    private Long province;

    /**
     * 市
     */
    @Excel(name = "市")
    @ApiModelProperty("市")
    private Long city;

    /**
     * 区
     */
    @Excel(name = "区")
    @ApiModelProperty("区")
    private Long district;

    /**
     * 街道
     */
    @Excel(name = "街道")
    @ApiModelProperty("街道")
    private Long street;

    /**
     * 村
     */
    @Excel(name = "村")
    @ApiModelProperty("村")
    private Long village;

    /**
     * 详细地址
     */
    @Excel(name = "详细地址")
    @ApiModelProperty("详细地址")
    private String address;

    /**
     * 门牌
     */
    @Excel(name = "门牌")
    @ApiModelProperty("门牌")
    private String door;



    /**
     * 月租
     */
    @Excel(name = "月租")
    @ApiModelProperty("月租")
    private BigDecimal monthPrice;

    /**
     * 开始月份 = 截止月份 - (余额 ÷ 月租)
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "缴费开始日期", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty("缴费开始日期")
    private Date startDate;


    /**
     * 截止日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "缴费截止日期", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty("缴费截止日期")
    private Date endDate;

    /**
     * 余额 = (截止月份- 开始月份 )*月租
     */
    private BigDecimal balance;

    /**
     * 房东---sysUser.id
     */
    @Excel(name = "房东")
    @ApiModelProperty("房东")
    private Long landlordId;


    private Long deptId;


    
    /**
     * 计算余额
     * 根据截止日期和月租计算剩余余额，过期会计算为负数
     * @return 计算得到的余额
     */
//    @JsonProperty("balance")
//    private BigDecimal getBalance() {
//        if (endDate == null || monthPrice == null) {
//            return BigDecimal.ZERO;
//        }
//
//        // 获取当前日期
//        Date now = new Date();
//
//        // 计算年月差
//        int yearDiff = DateUtil.year(endDate) - DateUtil.year(now);
//        int monthDiff = DateUtil.month(endDate) - DateUtil.month(now);
//
//        // 计算总月数差
//        int totalMonthDiff = yearDiff * 12 + monthDiff;
//
//        // 处理日期部分：如果当前日期的日部分大于截止日期的日部分，则多算一个月
//        int endDay = DateUtil.dayOfMonth(endDate);
//        int nowDay = DateUtil.dayOfMonth(now);
//
//        if (nowDay > endDay) {
//            totalMonthDiff--;
//        }
//
//        // 计算余额 = 月数差 * 月租
//        return monthPrice.multiply(BigDecimal.valueOf(totalMonthDiff));
//    }
    
    
}
